﻿using MochCraigslistDay19.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MochCraigslistDay19
{
    public sealed class ServiceSingleton
    {
        #region Private Class/Instance variables

        private static readonly Lazy<ServiceSingleton> lazy =
            new Lazy<ServiceSingleton>(() => new ServiceSingleton());

        private List<ProductVM> products = new List<ProductVM>();

        #endregion

        #region Properties
        public static ServiceSingleton Instance { get { return lazy.Value; } }
        #endregion

        #region Constructors
        private ServiceSingleton()
        {
            PopulateList();
        }

        #endregion

        #region Instance Methods
        public List<ProductVM> GetList()
        {
            return products;
        }

        private void PopulateList()
        {
            products.Add(new PeanutButterVM() 
            { 
                Brand = "Jiffy", 
                Description = "Mmmm good", 
                IsCreamy = true, 
                Price = 17, 
                Title = "Jiffy PB" 
            });
            products.Add(new PeanutButterVM()
            {
                Brand = "SmartBalance",
                Description = "Healthy one",
                IsCreamy = true,
                Price = 5,
                Title = "SmartBalance Healthy PB"
            });
            products.Add(new SmartPhoneVM()
            {
                Description = "The newsest iPhone woohoo",
                OperatingSystem = "iOS",
                Price = 328742837,
                Size = "finally big enough",
                Title = "iPhone 6"
            });
            products.Add(new SmartPhoneVM()
            {
                Description = "HTC One (the new one)",
                OperatingSystem = "Android",
                Price = 3264,
                Size = "big",
                Title = "HTC One"
            });
        }

        public void AddToProducts(ProductVM model)
        {
            products.Add(model);
        }
        #endregion
    }
}